<template>
  <div class="login-bg">
    <div class="login-bg-gradient"></div>
    <div class="login-brand">
      <div class="brand-logo-wrap">
        <img src="../assets/logo.png" alt="logo" class="logo-img" />
      </div>
      <div class="brand-name">VUE-VANT</div>
    </div>
    <div class="login-header">找回密码</div>
    <div class="login-form">
      <van-field
        v-model="phone"
        label="手机号"
        placeholder="请输入手机号"
        clearable
        maxlength="11"
        :border="false"
      >
        <template #left-icon>
          <van-icon name="phone-o" />
        </template>
      </van-field>
      <van-field
        v-model="code"
        label="验证码"
        placeholder="请输入验证码"
        clearable
        :border="false"
      >
        <template #left-icon>
          <van-icon name="comment-o" />
        </template>
        <template #button>
          <van-button
            size="small"
            type="primary"
            @click="onSendCode"
            :disabled="countdown > 0"
            >{{ countdown > 0 ? countdown + "s" : "获取验证码" }}</van-button
          >
        </template>
      </van-field>
      <van-field
        v-model="password"
        label="新密码"
        type="password"
        placeholder="请输入新密码"
        clearable
        :border="false"
      >
        <template #left-icon>
          <van-icon name="lock" />
        </template>
      </van-field>
      <van-button round block type="info" class="login-btn" @click="onReset"
        >重置密码</van-button
      >
    </div>
    <div class="login-footer">
      <span class="login-link" @click="$router.push('/login')">返回登录</span>
    </div>
  </div>
</template>

<script>
export default {
  name: "forgotPassword",
  data() {
    return {
      phone: "",
      code: "",
      password: "",
      countdown: 0,
      timer: null,
    };
  },
  methods: {
    onSendCode() {
      if (!/^1\d{10}$/.test(this.phone)) {
        this.$toast("请输入正确的手机号");
        return;
      }
      this.$toast("验证码已发送");
      this.countdown = 60;
      this.timer = setInterval(() => {
        this.countdown--;
        if (this.countdown <= 0) {
          clearInterval(this.timer);
        }
      }, 1000);
    },
    onReset() {
      if (!/^1\d{10}$/.test(this.phone)) {
        this.$toast("请输入正确的手机号");
        return;
      }
      if (!this.code) {
        this.$toast("请输入验证码");
        return;
      }
      if (!this.password || this.password.length < 6) {
        this.$toast("新密码至少6位");
        return;
      }
      this.$toast("密码重置成功");
      this.$router.push("/login");
    },
  },
  beforeDestroy() {
    if (this.timer) clearInterval(this.timer);
  },
};
</script>

<style scoped>
.login-bg {
  min-height: 100vh;
  background: #f6f8fa;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding-top: 0;
  position: relative;
  overflow: hidden;
}
.login-bg-gradient {
  position: absolute;
  top: 0;
  left: 0;
  width: 100vw;
  height: 320px;
  background: linear-gradient(135deg, #1677ff 0%, #42d0ea 100%);
  z-index: 0;
  border-bottom-left-radius: 60% 30%;
  border-bottom-right-radius: 60% 30%;
  filter: blur(0.5px);
}
.login-bg::before {
  content: "";
  position: absolute;
  top: 40px;
  left: 50%;
  transform: translateX(-50%);
  width: 220px;
  height: 220px;
  background: radial-gradient(circle at 60% 40%, #fff8 0%, #fff0 80%);
  z-index: 1;
  pointer-events: none;
}
.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 54px;
  margin-bottom: 10px;
  z-index: 2;
}
.brand-logo-wrap {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: linear-gradient(135deg, #42d0ea 0%, #1677ff 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 24px #1677ff22;
  margin-bottom: 8px;
}
.logo-img {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 2px 8px #1677ff22;
}
.brand-name {
  font-size: 22px;
  color: #fff;
  font-weight: bold;
  letter-spacing: 2px;
  text-shadow: 0 2px 8px #1677ff44;
}
.login-header {
  font-size: 22px;
  color: #fff;
  font-weight: bold;
  margin-bottom: 18px;
  letter-spacing: 2px;
  z-index: 2;
  text-shadow: 0 2px 8px #1677ff44;
}
.login-form {
  width: 92vw;
  max-width: 390px;
  background: #fff;
  border-radius: 28px;
  box-shadow: 0 8px 32px #1677ff18, 0 2px 8px #42d0ea11;
  padding: 32px 18px 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  margin-bottom: 18px;
  border: 1.5px solid #e3f0ff;
  z-index: 2;
  position: relative;
}
::v-deep .van-field {
  background: #fff;
  border-radius: 0;
  border: none;
  border-bottom: 1.5px solid #e3f0ff;
  box-shadow: none;
  margin-bottom: 18px;
  padding: 0 2px 0 0;
  transition: border-color 0.2s;
}
::v-deep .van-field--focused {
  border-bottom: 1.5px solid #1677ff;
  background: #fff;
  box-shadow: none;
}
::v-deep .van-field__left-icon {
  color: #b2cfff;
  font-size: 18px;
  background: none;
  padding: 0;
  margin-right: 4px;
}
::v-deep .van-field__label {
  color: #b0b8c9;
  font-size: 13px;
  font-weight: 400;
  padding-right: 6px;
}
.login-btn {
  margin-top: 16px;
  font-size: 18px;
  font-weight: bold;
  background: linear-gradient(90deg, #4fc3f7 0%, #1677ff 100%);
  border: none;
  box-shadow: 0 2px 12px #1677ff22;
  transition: box-shadow 0.2s, background 0.2s;
  border-radius: 999px;
  letter-spacing: 2px;
  height: 48px;
}
.login-btn:active {
  box-shadow: 0 1px 4px #1677ff33;
  background: linear-gradient(90deg, #1677ff 0%, #4fc3f7 100%);
}
.login-footer {
  display: flex;
  justify-content: center;
  gap: 28px;
  margin-top: 8px;
  z-index: 2;
}
.login-link {
  color: #1677ff;
  font-size: 14px;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.2s, text-decoration 0.2s;
}
.login-link:hover {
  opacity: 1;
  text-decoration: underline;
}
</style> 